package org.game;
import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.Iterator;

import com.sojoys.artifact.third.pcg.Pcg32;
import com.sojoys.artifact.tools.ToolRandom;

public class MyMouseAdapter 
{
	public static void main(String[] args)
	{
		new MyFrame("drawing");
	}
}

class MyFrame extends Frame
{
	ArrayList points=null;
	MyFrame(String s)
	{
		super(s);
		points=new ArrayList();
		setLayout(null);
		setBounds(300,300,400,300);	
		setBackground(new Color(204,204,255));
		setVisible(true);
		Pcg32 pcgX = new Pcg32(ToolRandom.randInt(0, 100),1);
		Pcg32 pcgY = new Pcg32(ToolRandom.randInt(0, 100),1);
//		Random randomX = new Random(ToolRandom.randInt(0, 100));
//		Random randomY = new Random(ToolRandom.randInt(0, 100));
		addMouseListener(new Monitor(pcgX,pcgY));
	}
	public void paint(Graphics g)//重写paint()方法
	{
		Iterator i=points.iterator();
		while(i.hasNext())
		{
			Point p=(Point)i.next();
			g.setColor(Color.BLUE);    //设置颜色
			g.fillOval(p.x,p.y,1,1); //画实心圆
		}
	}
	public void addPoint(Point p)
	{
		points.add(p);  //将点添加到容器中
	}
}

//class Monitor extends MouseAdapter
//{
//	Random randomX;
//	Random randomy;
//	
//	public Monitor(Random pcgX, Random pcgy) {
//		super();
//		this.randomX = pcgX;
//		this.randomy = pcgy;
//	}
//
//	public void mousePressed(MouseEvent e)
//	{
//		for (int i = 0; i < 1000; i++) {
//			MyFrame f=(MyFrame)e.getSource();
//			f.addPoint(new Point(randomX.nextInt(1000),randomy.nextInt(1000)));
//			f.repaint();
//		}
//	}
//}

class Monitor extends MouseAdapter
{
	Pcg32 pcgX;
	Pcg32 pcgy;
	
	public Monitor(Pcg32 pcgX, Pcg32 pcgy) {
		super();
		this.pcgX = pcgX;
		this.pcgy = pcgy;
	}

	public void mousePressed(MouseEvent e)
	{
		for (int i = 0; i < 1000; i++) {
			MyFrame f=(MyFrame)e.getSource();
			f.addPoint(new Point(pcgX.nextInt(1000),pcgy.nextInt(1000)));
			f.repaint();
		}
	}
}